from fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("Greeting Server")

@mcp.tool()
def say_hello(name: str) -> str:
    """Generate a personalized greeting message"""
    return f"Hello, {name}! Welcome to our MCP service!"

@mcp.tool()
def say_goodbye(name: str) -> str:
    """Generate a personalized goodbye message"""
    return f"Goodbye, {name}! Thanks for using our service!"

@mcp.resource("greeting://{name}")
def get_greeting_resource(name: str) -> str:
    """Get a greeting resource for the specified name"""
    return f"Greetings resource for {name}: Hello and welcome!"

# 定义加法工具
@mcp.tool()
def add(a: float, b: float) -> float:
    """两数相加"""
    return a + b

# 定义减法工具
@mcp.tool()
def subtract(a: float, b: float) -> float:
    """两数相减"""
    return a - b

# 定义乘法工具
@mcp.tool()
def multiply(a: float, b: float) -> float:
    """两数相乘"""
    return a * b

# 定义除法工具
@mcp.tool()
def divide(a: float, b: float) -> float:
    """两数相除"""
    if b == 0:
        raise ValueError("除数不能为零")
    return a / b

if __name__ == "__main__":
    mcp.run(transport="stdio")